package com.cn.response;

import com.cn.code.CodeEnum;
import com.sun.org.apache.bcel.internal.classfile.Code;

public class BaseResponse<T> {
    private String code;
    private String message;
    private Object data;

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    /**
     * 返回成功
     * @param data
     * @return
     * @param <T>
     */
    public static <T> BaseResponse<T> success(T data){
        BaseResponse<T> response = new BaseResponse<>();
        response.setCode(CodeEnum.SUCCESS.getCode());
        response.setData(data);
        response.setMessage(CodeEnum.SUCCESS.getMesssage());
        return response;
    }

    public static <T> BaseResponse<T> fail(String code,String message){
        BaseResponse<T> response = new BaseResponse<>();
        response.setCode(code);
        response.setMessage(message);
        return response;
    }

}
